import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:myapp/pages/newRoute.dart';
import 'package:myapp/pages/randomWords.dart';
import 'package:myapp/pages/tipRoute.dart';

class HomePage extends StatefulWidget {
  HomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  HomePageState createState() => new HomePageState();
}

class HomePageState extends State<HomePage> {
  int _counter = 0;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(title: new Text(widget.title)),
        body: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new Text('你已点击次数：'),
              new Text('$_counter',
                  style: Theme.of(context).textTheme.headline4),
              FlatButton(
                  onPressed: () {
                    Navigator.of(context).pushNamed("new_page", arguments: "测试");
                  },
                  child: Text("导航到新页面"),
                  textColor: Colors.blue),
              RaisedButton(
                onPressed: () async {
                  // 打开'tipRoute',并等待返回结果
                  var result = await Navigator.push(context,
                      MaterialPageRoute(builder: (context) {
                    return TipRoute(text: '我是提示XXXX');
                  }));
                  print("路由返回值:" + result);
                },
                child: Text("打开提示页"),
              ),
              RandomWordsWidget(),
              FlatButton(
                  onPressed: () {
                    Navigator.of(context).pushNamed("my_app_bar", arguments: "从homePage的参数");
                  },
                  child: Text("MyAppBar"),
                  textColor: Colors.blue)
            ],
          ),
        ),
        floatingActionButton: new FloatingActionButton(
          onPressed: _incrementCounter,
          tooltip: '增加',
          child: new Icon(Icons.add),
        ));
  }

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }
}
